package main

import "fmt"

func main(){
    // 3：长度，5：容量
    var number = make([]int,3,5)

    fmt.Printf("len = %d, cap = %d, slice = %v\n",len(number),cap(number),number)

    //追加元素1
    number = append(number,1)
    fmt.Printf("len = %d, cap = %d, slice = %v\n",len(number),cap(number),number)

    //追加元素2，此时容量已满
    number = append(number,2)
    fmt.Printf("len = %d, cap = %d, slice = %v\n",len(number),cap(number),number)

    //向容量cap已满的slice追加元素3
    number = append(number,3)
    fmt.Printf("len = %d, cap = %d, slice = %v\n",len(number),cap(number),number)

    fmt.Println("=========")

    //切片的扩容机制，append的时候，如果长度增加后超过容量，则将容量增加2倍
    var number2 = make([]int,3)
    fmt.Printf("len = %d, cap = %d, slice = %v\n",len(number2),cap(number2),number2)
    number2 = append(number2,1)
    fmt.Printf("len = %d, cap = %d, slice = %v\n",len(number2),cap(number2),number2)
}